package com.chushouya.controller.product.admin;

import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.general.framework.web.annotations.RepeatSubmit;
import com.chushouya.product.dto.admin.series.SeriesDetailDTO;
import com.chushouya.product.dto.admin.series.SeriesListDTO;
import com.chushouya.product.dto.admin.series.SeriesQuery;
import com.chushouya.product.service.admin.ProductSeriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = ServiceType.PLATFORM + "商品系列")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/series")
public class ProductSeriesController {

    @Resource
    private ProductSeriesService productSeriesService;

    @ApiOperation("获取商品系列")
    @GetMapping("/listProductSeries")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "类目id", required = true),
            @ApiImplicitParam(name = "brandId", value = "品牌id", required = true),
    })
    public Response<List<SeriesListDTO>> listProductSeries(Long categoryId, Long brandId) {
        SeriesQuery query = new SeriesQuery();
        query.setCategoryId(categoryId);
        query.setBrandId(brandId);
        return Response.success(productSeriesService.listProductSeries(query));
    }


    @ApiOperation("根据seriesId获取详细信息")
    @GetMapping("/getDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "seriesId", value = "系列id", required = true),
    })
    public Response<SeriesDetailDTO> getDetail(Long seriesId) {
        return Response.success(productSeriesService.getSeriesDetail(seriesId));
    }

    @ApiOperation("新增商品系列")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public Response<Long> add(@Validated @RequestBody SeriesDetailDTO category) {
        return Response.success(productSeriesService.addSeries(category));
    }

    @ApiOperation("修改商品系列")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<Long> edit(@Validated @RequestBody SeriesDetailDTO category) {
        return Response.success(productSeriesService.editSeries(category));
    }

    @ApiOperation("修改分类状态")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/editStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "seriesId", value = "系列id", required = true),
            @ApiImplicitParam(name = "status", value = "状态", required = true),
    })
    public Response<Long> editStatus(Long seriesId, Integer status) {
        return Response.success(productSeriesService.editSeriesStatus(seriesId, status));
    }

    @ApiOperation("删除商品系列")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "seriesId", value = "系列id", required = true)
    })
    public Response<Void> remove(Long seriesId) {
        productSeriesService.removeSeries(seriesId);
        return Response.success();
    }

}
